import Mock from 'mockjs'

const Random = Mock.Random
const token = Random.string('upper', 32, 32)

const account = 'admin'
const password = 'd6b6341a892afeeaeccc4ad0288b6693' // crypto-js加密，原密码：123456

interface IBody {
	body: string
}
// 登录
Mock.mock('/api/user/login', 'post', ({ body }: IBody) => {
	const data = JSON.parse(body)
	if (data.account === account && data.password === password) {
		return {
			code: 200,
			data: {
				id: 1,
				account: 'admin',
				token
			},
			msg: '查询成功'
		}
	} else {
		return {
			code: 400,
			msg: '账号或密码错误！'
		}
	}
})
// 用户信息
Mock.mock('/api/user/userinfo?id=1', 'get', () => {
	return {
		code: 200,
		data: {
			id: 1,
			account: 'admin',
			nickName: '管理员',
			avatar: 'https://cms.coderwyf.com/users/avatar/1',
			sex: '0',
			remark: '超级管理员',
			wechat: 'w912858686',
			occupation: '前端攻城狮'
		},
		message: '查询成功'
	}
})
